package com.soft.servlet;

import com.soft.entity.UserInfo;
import com.soft.service.Domain;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author kongz
 * @version 1.0 2021/6/7 9:21
 * @description 用户订购商品，商品添加到购物车
 */
@WebServlet(name = "DingGouServlet", urlPatterns = "/DingGou")
public class DingGouServlet extends HttpServlet {

    private Domain domain;
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        domain = new Domain();
        int goodsId = Integer.parseInt(req.getParameter("goodsId"));
        if (req.getSession().getAttribute("user") == null) {
            req.getSession().setAttribute("flag", 11);
            resp.sendRedirect("denglu.jsp");
            return;
        }
        UserInfo ui = (UserInfo) req.getSession().getAttribute("user");

        if (domain.newTrolleyInfo(goodsId, ui.getId())) {
            req.getSession().setAttribute("flag", 38);
            req.getRequestDispatcher("/GouWuCheList").forward(req, resp);
        } else {
            req.getSession().setAttribute("flag", 39);
            req.getRequestDispatcher("/GoodsShow").forward(req, resp);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
